﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace SMSController
{
    class LangPack
    {
        private static string xmlLocation;
        private static string language;
        private static Form tForm;
        private static XmlDocument xmlDoc;
        private static XmlNode xnFormLang;

        public LangPack(string configfileLocation,string lang,Form form)
        {
            xmlLocation = configfileLocation;
            language = lang;
            tForm = form;
            initialization();
        }
        private void initialization()
        {
            xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlLocation);
            XmlNode  xnLang = xmlDoc.SelectSingleNode(".//language[@name='"+ language +"']");
            xnFormLang = xnLang.SelectSingleNode(".//form[@name='" + tForm.Name + "']");
            
        }
        public string getFormText()
        {
            string formName = "";
            formName = xnFormLang.SelectSingleNode(".//control[@name='" + tForm.Name + "']").InnerText;
            //formName=xnLang.SelectSingleNode("//controller[@name='" + form.Name + "']").InnerText;
            return formName;
        }
        public string getControlText(string controlName)
        {
            string controltext = "";
            controltext = xnFormLang.SelectSingleNode(".//control[@name='" + controlName + "']").InnerText;
            return controltext;
        }
        public string[] getLanguageTexts()
        {
            XmlNodeList xlangs = xmlDoc.SelectNodes(".//language");
            string[] langTexts = new string[xlangs.Count];
            for (int i = 0; i < xlangs.Count; i++)
            {
                langTexts.SetValue(xlangs[i].Attributes[@"name"].Value.ToString().Trim(), i);
            }
            return langTexts;
        }
    }
}
